<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>扩展商城</legend>
            <blockquote class="layui-elem-quote">
                大部分功能插件以及模板可以通过此处获取,未获得云端授权请不要直接安装,避免触发自动卸载模块。
            </blockquote>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add"> 添加用户 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除用户 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#  if(d.state=='1'){ }}
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">安装</a>
            {{#  } else { }}
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">卸载</a>
            {{#  } }}
        </script>

    </div>
</div>

<script type="text/html" id="statusTemp">
    <input class="layui-btn-xs" type="checkbox" name="siteStatus" lay-skin="switch" lay-text="开启|关闭" value={{ d.id}}
    {{d.close=='on'?'checked':'off'}} lay-filter="status">
</script>

<script type="text/html" id="typeTemp">
    {{#  if(d.type==1){ }}
    <button class="layui-btn layui-btn-xs">站内</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-danger layui-btn-xs">直链</button>
    {{#  } }}
</script>

<script id="model" type="text/html">
    <form class="layui-form layui-form-pane" id="bannerset" lay-filter="bannerset" style="padding: 20px">
        <!--隐藏id-->
        <input name="siteId" type="hidden">
        <div class="layui-form-item">
            <label class="layui-form-label">轮播标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" placeholder="请输入轮播标题" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">展示海报</label>
            <div class="layui-input-block">
                <input type="text" name="pic" lay-verify="required" placeholder="请输入展示海报地址" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">播放地址</label>
            <div class="layui-input-block">
                <input type="text" name="url" lay-verify="required" placeholder="请输入播放地址" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="doSubmit" id="doSubmit" value="确认">
        </div>
    </form>

</script>

<script>
    layui.use(['form', 'table', 'miniPage', 'lycms'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            lycms = layui.lycms;
        form.render();

        table.render({
            elem: '#currentTableId',
            url: '/v1/admin/data/mill',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { field: 'title', title: '软件名称', width: 188, },
                { field: 'desc', title: '说明' },
                { field: 'edition', title: '版本', width: 80, align: "center" },
                { field: 'price', title: '价格', width: 80, align: "center" },
                { field: 'install', width: 120, title: '累计安装', align: "center", width: 120, sort: true },
                { field: 'time', title: '上架时间', align: "center", width: 180, sort: true },
                { field: 'state', title: '操作', width: 100, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });

        // 监听状态
        form.on('switch(status)', function (data) {
            $.ajax({
                url: "/ask/action/system/banner/edit",
                type: "post",
                dataType: "json",
                contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                data: {
                    id: data.value,
                    close: data.elem.checked ? 'on' : ''
                },
                success: function (res) {
                    if (res.code == 200) {
                        table.reload('LAY-user-manage'); //重载表格数据 成功后调用
                        layer.msg(res.msg, { time: 1500 });
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });

        // 监听操作
        table.on('tool(currentTableFilter)', function (obj) {
            // 操作
            lycms.millOperate(obj, "#downLoad", "doSubmit");
        });

    });
</script>